const state = {
  count: 200,
  num: 0,
};
const mutations = {
  /* mutations的方法会接受state作为第一个参数 */
  increase(state) {
    state.count++;
  },
  increaseN(state, payload) {
    state.count += payload.n;
  },
};
const actions = {
  // 默认参数是store 把commit解构出来
  increaseWait({ commit }) {
    setTimeout(() => {
      commit("increase");
    }, 1000);
  },
  increaseNWait({ commit }, payload) {
    setTimeout(() => {
      commit("increaseN", payload);
    }, 1000);
  },
};
const getters = {
  countSqrt(state) {
    return Math.sqrt(state.count);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
